<?php
$isReloadable = false;
require_once "../../../pers/inc.config.php";
require_once OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php';
require_once OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php';
require_once OVF_FS_WEB_ROOT.'/app/_inc/class.ovfForm.php';

$objSess->setReqSV('rcom', 'idAnag', 0);
$idAnag = intval($objSess->getSV('rcom', 'idAnag'));
$objSess->setReqSV('rcom', 'asez', 'referent');
$codSez = $objSess->getSV('rcom','asez');

$oForm = new ovfForm($codSez);

if (reqVar('azione') == 'salva') {
	$msgPag = conferma();
} 

if (reqVar('azione') == '') {
	$oForm->setDef();
}
$oForm->preForm();

$sCmdR = "";
$sCmdR .= "<a class=\"cmd1\" href=\"javascript:document.frm1.submit();\" >salva</a>\n";
$sCmdR .= cmdTorna();

// testata sezione anagrafica
$oFormTestaSez = new ovfForm('testasez');
//dbg_($oForm);
$sSql = "SELECT ".$oFormTestaSez->getCampiSelect()
	." FROM ovf_anagrafiche A WHERE id_anag = ".$idAnag;
$objDB->query($sSql);
if (!$oFormTestaSez->aCampiDB = $objDB->fetch()) {
	backOnErr("id. errato '".$idAnag."'");
}
$oFormTestaSez->db2form();

$sHtmlAnag = "<table class=\"tab1\" border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\" align='center'>";
$sHtmlAnag .= getHtmlRigaRif();
$sHtmlAnag .= $oFormTestaSez->getHtmlCampiView();
$sHtmlAnag .= "</table>";

$aOpz['sottotit'] = $sHtmlAnag;

testaHtml('Anagrafe',$oForm->descr.' - Nuova registrazione',$msgPag,'rcom',$aOpz);
?>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
			<? echo  $sCmdR;?>
      </td>
   </tr>
</table>
<?
echo getHtmlForm('frm1','',array('enctype'=>true));
echo getHtmlHidden('azione','salva');
echo getHtmlHidden('xsn',XSN);
?>
<table class="tab1" border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
	<?=getHtmlRigaRif();?>
   <tr>
      <td class="tit1" colspan='20' align='center'><?=$oForm->descr?></td>
   </tr>
<?
echo $oForm->getHtmlCampiForm();
?>
</table>
<table border="0" cellpadding="3" cellspacing="1" width="100%" align='center'>
   <tr>
      <td class="cmd1" align="right">
         <? echo  $sCmdR;?>
      </td>
   </tr>
</table>
<?
echo "</form>\n";
codaHtml();
exit();
function conferma() {
	global $objDB, $objSess, $oForm;
	$idAnag = intval($objSess->getSV('rcom', 'idAnag'));
	$codSez = $objSess->getSV('rcom','asez');
	
	$msg = '';
	//dbg_($oForm);
	$msg .= $oForm->formCheck();
	
	if ($msg != '') {
		return $msg;
	}
	$oForm->form2db();
	$oForm->aCampiDB['S_id_anag'] = $idAnag;
	
	$sSql = $oForm->getInsertDb("ovf_sez_".$codSez);
	//return $sSql;
	$objDB->exec($sSql);
	
	header("Location: ".urlTorna(_t("registrazione effettuata")));
	exit();
}
